<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            const students = [
                {
                    name: '张三',
                    class: 1,
                    math: 100,
                    language: 80,
                    english: 60,
                    physics: 80,
                    chemistry: 60,
                },
                {
                    name: '李四',
                    class: 1,
                    math: 120,
                    language: 60,
                    english: 20,
                    physics: 100,
                    chemistry: 100,
                },
                {
                    name: '王五',
                    class: 1,
                    math: 140,
                    language: 90,
                    english: 120,
                    physics: 60,
                    chemistry: 60,
                },

                {
                    name: '苑博',
                    class: 2,
                    math: 140,
                    language: 90,
                    english: 120,
                    physics: 60,
                    chemistry: 60,
                },

                {
                    name: '文轩',
                    class: 2,
                    math: 110,
                    language: 60,
                    english: 120,
                    physics: 30,
                    chemistry: 30,
                },

                {
                    name: '聪健',
                    class: 3,
                    math: 110,
                    language: 60,
                    english: 120,
                    physics: 30,
                    chemistry: 30,
                },
                {
                    name: '烨磊',
                    class: 3,
                    math: 88,
                    language: 70,
                    english: 100,
                    physics: 45,
                    chemistry: 56,
                },
                {
                    name: '烨霖',
                    class: 3,
                    math: 120,
                    language: 60,
                    english: 100,
                    physics: 50,
                    chemistry: 60,
                },
                {
                    name: '荣轩',
                    class: 2,
                    math: 90,
                    language: 160,
                    english: 120,
                    physics: 50,
                    chemistry: 50,
                },
                {
                    name: '懿轩',
                    class: 2,
                    math: 100,
                    language: 90,
                    english: 120,
                    physics: 90,
                    chemistry: 90,
                },
                {
                    name: '擎苍',
                    class: 2,
                    math: 100,
                    language: 130,
                    english: 120,
                    physics: 10,
                    chemistry: 40,
                },
                {
                    name: '绍齐',
                    class: 1,
                    math: 100,
                    language: 90,
                    english: 120,
                    physics: 60,
                    chemistry: 60,
                },
                {
                    name: '皓轩',
                    class: 1,
                    math: 100,
                    language: 120,
                    english: 120,
                    physics: 50,
                    chemistry: 50,
                },
                {
                    name: '鹭洋',
                    class: 1,
                    math: 100,
                    language: 80,
                    english: 120,
                    physics: 30,
                    chemistry: 90,
                },
                {
                    name: '潇然',
                    class: 2,
                    math: 110,
                    language: 92,
                    english: 114,
                    physics: 56,
                    chemistry: 74,
                },
                {
                    name: '智宸',
                    class: 1,
                    math: 100,
                    language: 100,
                    english: 100,
                    physics: 30,
                    chemistry: 30,
                },
                {
                    name: '风华',
                    class: 1,
                    math: 110,
                    language: 60,
                    english: 120,
                    physics: 80,
                    chemistry: 79,
                },
                {
                    name: '雨泽',
                    class: 1,
                    math: 100,
                    language: 68,
                    english: 115,
                    physics: 36,
                    chemistry: 83,
                },
                {
                    name: '浩然',
                    class: 2,
                    math: 105,
                    language: 116,
                    english: 120,
                    physics: 90,
                    chemistry: 60,
                },
                {
                    name: '瑾瑜',
                    class: 3,
                    math: 110,
                    language: 60,
                    english: 120,
                    physics: 99,
                    chemistry: 98,
                },
            ];
            function handleData(arr) {
                return arr.reduce((t, v) => {
                    // 判断当前班级是否已经创建，如果已经创建，就直接 push 新数据，如果没有创建，就使用
                    if (t[v.class]) {
                        t[v.class].push(v);
                    } else {
                        t[v.class] = [v];
                    }
                    return t;
                }, {});
            }
            console.log(handleData(students));
        </script>
    </body>
</html>
